const { defineConfig } = require('@vue/cli-service');
const webpack = require('webpack');

module.exports = defineConfig({
  publicPath: '/',
  // 输出文件目录
  outputDir: 'dist',
  // 静态资源目录
  assetsDir: 'static',
  // 是否使用包含运行时编译器的 Vue 构建版本
  runtimeCompiler: false,

  transpileDependencies: true,
  lintOnSave: true,
  chainWebpack(chain) {
    chain.resolve.fallback = {
      crypto: require.resolve('crypto-browserify'),
      stream: require.resolve('stream-browserify'),
      vm: false, // 添加这一行
    };
    chain.plugin('env').use(
      new webpack.ProvidePlugin({
        Buffer: ['buffer', 'Buffer'],
      })
    );
    chain.resolve.alias.set('crypto', 'crypto-browserify');
    chain.resolve.alias.set('stream', 'stream-browserify');
  },
  devServer: {
    client: {
      overlay: false,
    },
    proxy: {
      '/api': {
        target: 'http://localhost:5000',
        changeOrigin: true,
        pathRewrite: { '^/api': '' },
      },
      '/ws': {
        target: 'ws://localhost:8765',
        ws: true,
        changeOrigin: true,
        pathRewrite: { '^/ws': '' },
      },
    },
    webSocketServer: false,
  },
  configureWebpack: {
    devtool:
      process.env.NODE_ENV === 'production'
        ? 'nosources-source-map'
        : 'source-map',
  },
});
